<?php if(!defined('BASEPATH')) exit("Sorry, what you're looking not found.");
class C_level extends Nvl_Controller{
    function __construct(){
        parent::__construct();
        session_start();
		$this->__checkSession();
        $this->load->model('m_level');
    }

    function index(){
        $this->load->view('pages/v_level');
    }

    function get_list(){
        $pagenum = $this->input->numeric('pagenum', 'get');
        $pagesize = $this->input->numeric('pagesize', 'get');
		$start = $pagenum * $pagesize;
		$end = $start + $pagesize;
		$search_text = $this->input->get('search_text');
		$result = $this->m_level->get_list($start, $end, $search_text);
		echo $result;
    }
	
	function save(){
		$params = json_decode($this->input->post("params"));
		extract(get_object_vars($params));
		$data = array(
			"level_nama"=>$form_data->level_nama,
			"level_keterangan"=>$form_data->level_keterangan,
			"level_aktif"=>1
		);
		$level_id = $this->m_level->__save($data, help_numeric($params->level_id), FALSE, TRUE);
		$data_skor = array();
		foreach($detail as $sub){
			if($sub->skor_angka != ''){
				$data_skor[] = array(
					"skor_level_id"=>$level_id,
					"skor_juara_id"=>$sub->skor_juara_id,
					"skor_angka"=>$sub->skor_angka
				);
			}
		}
		$this->db->insert_batch("t_skor", $data_skor);
		echo $level_id;
	}
	
	function delete(){
		$level_id = $this->input->numeric('level_id');
		$result = $this->m_level->__save(array('level_aktif'=>'0'), $level_id);
		echo $result;
	}
	
	function get_list_skor(){
		$level_id = $this->input->numeric('level_id');
		$result = $this->m_level->get_list_skor($level_id);
		echo $result;
	}
}